/**
 * 
 */
package org.sigedu.security.pages;

import java.util.Arrays;

import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.ApplicationStateManager;
import org.chenillekit.access.WebSessionUser;
import org.sigedu.security.model.SessionUser;
import org.slf4j.Logger;

/**
 * @author sebas
 * 
 * @version $$Id$$
 */
@IncludeStylesheet("login.css")
public class Login {
	@Property
	@Persist
	private String login;

	@Property
	@Persist
	private String password;

	@Inject
	private ApplicationStateManager manager;

	@Inject
	private Logger logger;

	void beginRender() {
		logger.info("User: " + toString(manager.getIfExists(SessionUser.class)) + " ("
				+ toString(manager.getIfExists(WebSessionUser.class)) + ")");
	}

	private String toString(final WebSessionUser u) {
		return u == null ? "<null>" : u.getRoleWeight() + " - "
				+ (u.getGroups() != null ? Arrays.asList(u.getGroups()) : "[])");
	}
}
